package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    void deleteByIds(@Param("ids") List<Long> ids);

    @Select("select * from dish where id = #{id}")
    Dish getByid(Long id);

    /**
     * 查询指定ID的菜品中状态为1(售卖中)的数量
     * @param ids 菜品ID列表
     * @return 状态为1的菜品数量
     */
    int countSellingDishes(@Param("ids") List<Long> ids);

    DishVO getByIdWithFlavor(Long id);

    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    @Delete("delete from  dish_flavor WHERE dish_id = #{id}")
    void deleteById(Long id);

    @Select("select * from dish where category_id = #{categoryId} order by create_time desc")
    List<Dish> getByCategoryId(Long categoryId);

    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);


}
